
/**  
* @Title: Application.java
* @Package com.kutuzov
* @Description: TODO(用一句话描述该文件做什么)
* @author xym
* @date 2017年7月14日
* @version V1.0  
*/

package com.kutuzov;

import javax.sql.DataSource;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @ClassName: Application
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author xym
 * @date 2017年7月14日
 *
 */
//@Configuration
//@ComponentScan
//@EnableAutoConfiguration
// spring boot1.2+可以直接用下面这个注解替换上面三个.
@SpringBootApplication(scanBasePackages="com.kutuzov")
// 开启事务支持，相当于XML中配置<tx:annotation-driven />配置方式，然后在访问Service方法上标注@Transactional注解即可
@EnableTransactionManagement
// 如果指定MapperScan 则每个Mapper上加上 @Mapper注解(每个Dao上)
@MapperScan("com.kutuzov.spring4.boot.dao")
// extends SpringBootServletInitializer MVC配置
public class Application extends SpringBootServletInitializer {
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
	
	/*// 用户自定义事务管理方法
	@Bean
	public PlatformTransactionManager txManager(DataSource dataSource) {
		return new DataSourceTransactionManager(dataSource);
	}*/
	
	// 分布式事务 Atomikos, Bitronix分布式事务处理框架
	
	// MVC配置 重写SpringBootServletInitializer的configure()方法
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(Application.class);
	}
}
